<template>
  <div class="layout-warpper">
    <div class="layout-search">
      <!--
        label-width="80px" -->
      <el-form
        ref="formSearch"
        :model="formSearch"
        :rules="rules"
        :inline="true"
        class="form-search font-right"
        size="normal"
      >
        <!-- {{ formSearch }} -->
        <el-form-item class="btn">
          <el-button
            v-if="formSearch.industry && formSearch.tenderMode && formSearch.status"
            type="primary"
            icon="el-icon-circle-plus-outline"
            @click="addShiXiangFn('xz')"
          >
            新增见证事项
          </el-button>
        </el-form-item>
        <el-form-item label="行业类型：">
          <!-- clearable -->
          <el-select v-model="formSearch.industry" style="width: 150px" placeholder="请选择" @change="industryChangeFn">
            <el-option
              v-for="item in TASKOBJ.industryTypeAndIndustry"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="交易方式：">
          <!-- clearable -->
          <el-select
            v-model="formSearch.tenderMode"
            placeholder="请选择"
            style="width: 150px"
            @change="tenderModeChangeFn"
          >
            <el-option v-for="item in liveStatusArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="见证环节：">
          <!-- clearable -->
          <!-- {{ statusOptions }} -->
          <el-select v-model="formSearch.status" style="width: 100px" placeholder="请选择" @change="handleSearchFn">
            <el-option v-for="item in statusOptions" :key="item.abridge" :label="item.label" :value="item.abridge" />
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="layout-body">
      <el-table v-loading="loading" :data="tableTaskList" style="width: 100%" height="100%">
        <el-table-column type="expand" width="20">
          <template slot-scope="scope">
            <div class="zhangC">
              <div class="zhangC-1">正常：</div>
              <el-radio-group
                v-for="(item, index) in scope.row.normalList"
                :key="index"
                v-model="item.defaultItem"
                class="zhangC-radio"
              >
                <el-tooltip class="item" effect="dark" :content="item.itemName" placement="top-start">
                  <el-radio v-if="item.itemStatus == 'NORMAL_TYPE'" disabled label="DEFAULT">
                    {{ item.itemName.substring(0, 29) }}{{ item.itemName.length > 29 ? "..." : "" }}
                  </el-radio>
                </el-tooltip>
              </el-radio-group>
            </div>
            <div class="yiC">
              <div class="yiC-1">异常：</div>
              <el-radio-group
                v-for="(item, index) in scope.row.exceptionList"
                :key="index"
                v-model="item.defaultItem"
                class="yiC-radio"
              >
                <el-tooltip class="item" effect="dark" :content="item.itemName" placement="top-start">
                  <el-radio v-if="item.itemStatus == 'EXCEPTION_TYPE'" label="DEFAULT" disabled>
                    {{ item.itemName.substring(0, 29) }}{{ item.itemName.length > 29 ? "..." : "" }}
                  </el-radio>
                </el-tooltip>
              </el-radio-group>
            </div>
          </template>
        </el-table-column>
        <el-table-column type="index" :index="indexFn" label="序号" align="left">
          <template slot-scope="scope">
            {{ (pageObj.currentPage - 1) * pageObj.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="itemName" label="见证事项名称" />
        <el-table-column prop="address" label="操作" width="180">
          <template slot-scope="scope">
            <el-button type="text" size="default" @click="updateMattersFn(scope.row)">编辑</el-button>
            <el-button type="text" size="default" @click="deleteData(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="layout-footer ui-pt10">
      <!-- {{ pageObj.total + " " + pageObj.pageSize }} -->
      <pagination
        v-if="pageObj.total > pageObj.pageSizes[0]"
        :total="pageObj.total"
        :page.sync="pageObj.currentPage"
        :limit.sync="pageObj.pageSize"
        :page-sizes="pageObj.pageSizes"
        @pagination="subtaskListFn"
      />
    </div>
    <!-- 新增弹框 -->
    <gWitnessMatterDialog
      ref="mattersDialog"
      :industry-type-and-industry-arr="industryTypeAndIndustryArr"
      :live-status-arr="liveStatusArr"
      :task-allocation="statusOptions"
      :form-init-data="formInitData"
      :shixiang-init-data="shixiangInitData"
      :order-init-total="orderTotal"
      :task-obj="TASKOBJ"
      :show="AddVisible"
      :type="dialogType"
      @close="downInfoCloseFn"
      @getShixiangDataFn="getShixiangDataFn"
      @submitFn="mattersSubmitFn"
    />
    <!-- 删除弹框 -->
    <el-dialog
      title="提示"
      :visible.sync="deleteLiveVisible"
      width="500px"
      class="stop-live-dialog"
      @close="stopLiveClosemidelete"
    >
      <div class="info">
        <i class="el-icon-warning" style="color: #e6ad00; font-size: 18px; vertical-align: top" />
        确定要删除吗？
      </div>
      <span slot="footer">
        <el-button type="primary" :loading="deleteBtnFlag" @click="deleteSubmit">确定</el-button>
        <el-button @click="deleteLiveVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  // import ExpertList from "./expertList.vue";
  // import expertSignIn from "./expertSignIn.vue";
  import {
    moduleInit,
    newAddPeople,
    itemDictUpdate,
    itemRuleList,
    itemDictionaryAll,
    newAddSystem,
    itemDelete
    // shixiangDictList
  } from "../../../api/api.js";
  // import TopStatus from "../../../components/TopStatus.vue";
  import gWitnessMatterDialog from "../../../components/dialog/WitnessMattersDialog.vue";
  // import WitnessRecord from "../../../components/dialog/WitnessRecord.vue";
  // import SubTaskTable from "../components/SubTaskTable.vue";
  // import SIdentify from "../../../components/sidentify.vue";
  export default {
    components: {
      // TopStatus,
      gWitnessMatterDialog
      // SIdentify,
      // WitnessRecord,
      // SubTaskTable
    },
    data() {
      return {
        xugai: "",
        deleteBtnFlag: false,
        TASKOBJ: {},
        shixiangDataChildrenZC: [],
        shixiangDataChildrenYC: [],
        tenderModeData: [],
        industryTypeAndIndustryArr: [],
        loadingBtn: false,
        loading: false,
        deleteLiveVisible: false,
        dialogType: "",
        AddVisible: false,
        AddVisibleBj: false,
        liveStatusArr: [],
        roomNameList: [],
        deleteIds: [],
        FormDataLoading: false,
        tableTaskListAll: [],
        rowList: "",
        formInitData: {},
        FormData: {
          industry: "",
          tenderMode: "",
          status: "",
          valueCode: "YES",
          jianzheng: "",
          domains: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "NORMAL_TYPE"
            }
          ],
          domainss: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            }
          ]
        },
        statusOptions: [],
        formSearch: {
          date: "",
          keyWord: "",
          industry: "",
          tenderMode: "",
          status: ""
        },
        rulesData: {
          valueCode: [{ required: true, message: "请选择任务分配", trigger: "blur" }],
          jianzheng: [
            {
              required: true,
              message: "请选择见证事项名称",
              trigger: ["blur", "change"]
            }
          ],
          jianzhengs: [{ required: true, message: "请选择见证事项名称", trigger: "change" }]
        },
        rules: {},
        currRowData: {},
        identifyCode: "",
        shixiangData: [],
        shixiangInitData: [],
        orderTotal: -1,
        tableTaskList: [],
        tableTaskLists: [],
        pageObj: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          pageSizes: [10, 20, 30]
        },
        pageSizes: [10, 20, 30],
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        }
      };
    },
    async created() {
      await this.moduleInitFn();
      // await this.handleSearchFn();
    },
    methods: {
      // 验证码开始
      refreshCode() {
        this.identifyCode = this.makeCode("1234567890", 4);
      },
      deleteData(row) {
        this.deleteLiveVisible = true;
        this.deleteBtnFlag = false;
        this.rowList = row;
      },
      // 删除
      async deleteDataList() {
        const arr = [];
        this.rowList.children.forEach((item) => {
          arr.push(item.itemConfigId);
        });
        // arr.push(this.rowList.itemConfigId);
        try {
          const p = {
            itemIds: arr
          };
          const res = await itemDelete(p);
          if (res.success) {
            this.loading = false;
            this.AddVisible = false;
            this.$message({
              type: "success",
              message: "删除成功",
              single: true
            });
            // this.handleSearchFn();
            this.listPageDictionaryFn();
            this.deleteLiveVisible = false;
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        setTimeout(() => {
          this.deleteBtnFlag = false;
        }, 1000);
      },
      // 编辑
      updateMattersFn(row) {
        console.log("row", row);
        this.currRowData = row;
        this.xugai = "XG";
        this.dialogType = "edit";
        const arr = [];
        const arrs = [];
        // const arr = exceptionList;
        // const arrs = normalList;
        // normalList;
        // 正常
        row.normalList.forEach((item) => {
          console.log("item", item.itemName);
          arr.push({
            isSystem: item.isSystem,
            itemStatus: item.itemStatus,
            defaultItem: item.defaultItem,
            sceneRecord: item.itemName,
            itemCode: item.itemName,
            record: item.record,
            itemConfigId: item.itemConfigId
          });
        });
        // 异常
        row.exceptionList.forEach((item) => {
          arrs.push({
            isSystem: item.isSystem,
            itemStatus: item.itemStatus,
            defaultItem: item.defaultItem,
            sceneRecord: item.itemName,
            itemCode: item.itemName,
            record: item.record,
            itemConfigId: item.itemConfigId
          });
        });
        // row.children.forEach((item) => {
        //   console.log("item", item.itemName);
        //   if (item.itemStatus === "NORMAL_TYPE") {
        //     arr.push({
        //       isSystem: item.isSystem,
        //       itemStatus: item.itemStatus,
        //       defaultItem: item.defaultItem,
        //       sceneRecord: item.itemName,
        //       itemCode: item.itemName,
        //       record: item.record,
        //       itemConfigId: item.itemConfigId
        //     });
        //   } else {
        //     arrs.push({
        //       isSystem: item.isSystem,
        //       itemStatus: item.itemStatus,
        //       defaultItem: item.defaultItem,
        //       sceneRecord: item.itemName,
        //       itemCode: item.itemName,
        //       record: item.record,
        //       itemConfigId: item.itemConfigId
        //     });
        //   }
        // });
        this.formInitData = {
          industry: this.formSearch.industry,
          tenderMode: this.formSearch.tenderMode,
          status: this.formSearch.status,
          scenes: [row.witnessScene],
          // statusArr: [this.formSearch.status],
          valueCode: row.isSystem,
          jianzheng: row.itemName,
          itemOrder: row.itemOrder,
          domains: arr,
          domainss: arrs
        };
        console.log("this.formInitData", this.formInitData);
        this.dialogType = "edit";
        // this.AddVisibleBj = true;
        this.AddVisible = true;
      },
      downInfoCloseFn() {
        this.AddVisible = false;
        this.orderTotal = -1;
        this.shixiangDataChildrenYC.map((titem) => {
          titem.disabled = false;
        });
        this.shixiangDataChildrenZC.map((titem) => {
          titem.disabled = false;
        });
        this.shixiangDataChildrenZC = [];
        this.shixiangDataChildrenYC = [];
      },
      // 删除弹框
      stopLiveClosemidelete() {
        this.deleteLiveVisible = false;
      },
      // 确认删除
      deleteSubmit() {
        this.deleteBtnFlag = true;
        this.deleteDataList();
        this.shixiangData.forEach((j) => {
          if (this.rowList.itemName === j.itemName) {
            j.disabled = false;
          }
        });
      },
      indexFn(index) {
        return index + 1 + (this.pageObj.currentPage - 1) * this.pageObj.pageSize;
      },
      async addShiXiangFn(xz) {
        this.AddVisible = true;
        this.FormDataLoading = true;
        this.xugai = xz;
        this.dialogType = "add";
        this.formInitData = {
          industry: this.formSearch.industry,
          tenderMode: this.formSearch.tenderMode,
          status: this.formSearch.status,
          statusArr: [this.formSearch.status],
          scenes: ["EXISTING"],
          valueCode: "YES",
          jianzheng: "",
          domains: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "NORMAL_TYPE"
            }
          ],
          domainss: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            }
          ]
        };
        // }
        // // 邀请招标
        // if (this.formSearch.tenderMode === "INVITE_BIDDING") {
        //   console.log(this.tableTaskListAll, this.shixiangData);
        //   this.tableTaskListAll.forEach((i) => {
        //     this.shixiangData.forEach((j) => {
        //       if (i.itemName === j.itemName) {
        //         j.disabled = true;
        //       }
        //     });
        //   });
        // }
        await this.shixiangDataFn();
        this.FormDataLoading = false;
        // this.shixiangDataChange();
        // this.pageObj.total = 0;
        // this.pageObj.currentPage = -1;
        // this.subtaskListFn();
      },
      getShixiangDataFn(obj) {
        console.log("getShixiangDataFn", obj);
        clearTimeout(this.setTimeFlag);
        this.setTimeFlag = setTimeout(async () => {
          await this.shixiangDataFn(obj);
        }, 100);
      },
      async shixiangDataFn(obj) {
        console.log("obj====", obj);
        if (obj) {
          this.formSearch.industry = obj.industry;
          this.formSearch.tenderMode = obj.tenderMode;
          this.formSearch.status = obj.status;
          this.$nextTick(async () => {
            await this.itemDictionaryAllFn(obj);
            if (obj.init !== "init" && this.dialogType === "add") {
              this.listPageDictionaryFn();
              // change会重复调接口
              await this.industryChangeFn(obj.industry);
            }
          });
          // this.handleSearchFn();
        }
        // await this.subtaskListAllFn(obj);
      },
      radioBox(e) {
        this.shixiangDataChildrenYC.map((titem) => {
          titem.disabled = false;
        });
        this.shixiangDataChildrenZC.map((titem) => {
          titem.disabled = false;
        });
        if (this.FormData.valueCode === "NO") {
          this.$refs.FormDataAdd.resetFields(); // 清空
          this.FormData.valueCode = "NO"; // 赋值
        } else {
          this.$refs.FormDataAdd.resetFields(); // 清空
          this.FormData.valueCode = "YES"; // 赋值
        }
        this.shixiangDataChildrenYC = [];
        this.shixiangDataChildrenZC = [];
        this.FormData = {
          valueCode: e,
          jianzheng: "",
          domains: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "NORMAL_TYPE"
            }
          ],
          domainss: [
            {
              itemCode: "",
              sceneRecord: "",
              defaultItem: "DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            }
          ]
        };
      },
      // 见证取消新增
      // cancelSubmitFn(formName) {
      //   this.tableTaskList.forEach((i) => {
      //     this.shixiangData.forEach((j) => {
      //       if (i.itemName == j.itemName && i.tenderMode == j.tenderMode) {
      //         j.disabled = false;
      //       }
      //     });
      //   });
      //   this.$refs[formName].resetFields();
      //   this.AddVisible = false;
      //   this.shixiangDataChildrenYC.map((titem) => {
      //     titem.disabled = false;
      //   });
      //   this.shixiangDataChildrenZC.map((titem) => {
      //     titem.disabled = false;
      //   });
      //   this.shixiangDataChildrenZC = [];
      //   this.shixiangDataChildrenYC = [];
      //   this.FormData = {
      //     valueCode: "YES",
      //     jianzheng: "",
      //     domains: [
      //       {
      //         itemCode: "",
      //         sceneRecord: "",
      //         defaultItem: "DEFAULT",
      //         itemStatus: "NORMAL_TYPE"
      //       }
      //     ],
      //     domainss: [
      //       {
      //         itemCode: "",
      //         sceneRecord: "",
      //         defaultItem: "DEFAULT",
      //         itemStatus: "EXCEPTION_TYPE"
      //       }
      //     ]
      //   };
      // },
      // 见证确认新增
      downInfoSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.FormData.valueCode === "NO") {
              this.shouDong();
            } else {
              this.xiTongAdd();
            }
          }
        });
      },
      // 见证确认编辑
      downInfoSubmitBJ(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.itemDictUpdateFn(this.currRowData);
          } else {
            return false;
          }
        });
      },
      mattersSubmitFn(fn, obj) {
        console.log("fn,", fn);
        console.log("obj,", obj);
        // xiTongAdd
        if (fn === "itemDictUpdateFn") {
          this[fn]({}, obj);
        } else {
          this[fn](obj);
        }
      },
      // 自定义新增
      async shouDong(obj = {}) {
        this.loadingBtn = true;
        try {
          const arr = [];
          this.FormData.domains.forEach((item) => {
            arr.push(item);
          });
          this.FormData.domainss.forEach((jtem) => {
            arr.push(jtem);
          });
          const p = {
            // industryType: this.formSearch.industry,
            // tenderMode: this.formSearch.tenderMode,
            // segment: this.formSearch.status,
            // itemRecord: this.FormData.jianzheng,
            // sceneRecords: arr
            industryType: obj.industry || this.formSearch.industry,
            tenderMode: obj.tenderMode || this.formSearch.tenderMode,
            segment: obj.statusArr || [obj.status || this.formSearch.status],
            itemRecord: obj.jianzheng || this.FormData.jianzheng,
            sceneRecords: obj.arr || arr,
            witnessScene: obj.witnessScene || "EXISTING"
            // itemOrder: obj.itemOrder
          };
          if (!(Array.isArray(p.segment) && p.segment.length > 1)) {
            p.itemOrder = obj.itemOrder;
          }
          const res = await newAddPeople(p);
          if (res.success) {
            this.loading = false;
            this.AddVisible = false;
            this.$message({
              type: "success",
              message: "新增成功",
              single: true
            });
            // 搜索下拉初始化 添加联动后自定义新增、系统新增不需要执行searchInitFn by link 20220727
            // this.searchInitFn(p);
            this.subtaskListFn();
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        // this.$refs.mattersDialog.$options.loadingBtn = false;
        this.loadingBtn = false;
      },
      searchInitFn(p) {
        console.log("searchInitFn", p);
        this.FormData.valueCode = "";
        this.formSearch.industry = p.industryType;
        this.formSearch.tenderMode = p.tenderMode;
        if (Array.isArray(p.segment)) {
          [this.formSearch.status] = p.segment;
        } else {
          this.formSearch.status = p.segment;
        }
        this.industryChangeFn(p.industryType);
        this.tenderModeChangeFn(p.tenderMode);
      },
      // 系统新增
      async xiTongAdd(obj = {}) {
        this.loadingBtn = true;
        try {
          const arr = [];
          this.FormData.domains.forEach((item) => {
            if (item.itemCode.length === 32) {
              // item.sceneRecord = item.sceneRecord;
            } else {
              // item.sceneRecord = item.sceneRecord;
              item.itemCode = "";
            }
            arr.push(item);
          });
          this.FormData.domainss.forEach((jtem) => {
            if (jtem.itemCode.length === 32) {
              // jtem.sceneRecord = jtem.sceneRecord;
            } else {
              // jtem.sceneRecord = jtem.sceneRecord;
              jtem.itemCode = "";
            }
            arr.push(jtem);
          });
          const p = {
            industryType: obj.industry || this.formSearch.industry,
            tenderMode: obj.tenderMode || this.formSearch.tenderMode,
            segment: obj.status || this.formSearch.status,
            parentItemCode: obj.jianzheng || this.FormData.jianzheng,
            sceneRecords: obj.arr || arr,
            itemOrder: obj.itemOrder
          };
          const res = await newAddSystem(p);
          if (res.success) {
            this.loading = false;
            this.AddVisible = false;
            this.$message({
              type: "success",
              message: "新增成功",
              single: true
            });
            this.loadingBtn = false;
            // 搜索下拉初始化 添加联动后自定义新增、系统新增不需要执行searchInitFn by link 20220727
            // this.searchInitFn(p);
            this.subtaskListFn();
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      // 事项修改
      async itemDictUpdateFn(row, obj = {}) {
        this.loadingBtn = true;
        try {
          const arr = [];
          if (this.FormData.valueCode === "NO") {
            this.FormData.domains.forEach((item) => {
              arr.push(item);
            });
            this.FormData.domainss.forEach((jtem) => {
              arr.push(jtem);
            });
          } else {
            this.FormData.domains.forEach((item) => {
              arr.push({
                defaultItem: item.defaultItem,
                itemStatus: item.itemStatus,
                itemConfigId: item.itemConfigId,
                sceneRecord: item.sceneRecord
              });
            });
            this.FormData.domainss.forEach((jtem) => {
              arr.push({
                defaultItem: jtem.defaultItem,
                itemStatus: jtem.itemStatus,
                itemConfigId: jtem.itemConfigId,
                sceneRecord: jtem.sceneRecord
              });
            });
          }
          // this.currRowData;
          const p = {
            deleteIds: obj.deleteIds || this.deleteIds,
            parentItemCode: this.currRowData.itemCode,
            parentItemName: obj.jianzheng || this.FormData.jianzheng,
            industryType: this.currRowData.industryType,
            tenderMode: this.currRowData.tenderMode,
            industry: this.currRowData.tenderMode,
            segment: this.currRowData.segment,
            sceneRecords: obj.arr || arr,
            witnessScene: obj.witnessScene || null,
            itemOrder: obj.itemOrder
          };
          //  if (!(Array.isArray(p.segment) && p.segment.length > 1)) {
          //   p.itemOrder = obj.itemOrder;
          // }
          const res = await itemDictUpdate(p);
          if (res.success) {
            this.loading = false;
            this.AddVisibleBj = false;
            this.$message({
              type: "success",
              message: "修改成功",
              single: true
            });
            this.loadingBtn = false;
            this.AddVisible = false;
            await this.subtaskListFn();
            this.deleteIds = [];
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      async itemDictionaryAllFn(obj = {}) {
        console.log("obj", obj);
        if (!obj.industry) {
          return;
        }
        try {
          //   identify: this.identify,
          //   tenderMode: this.tenderMode,
          //   status: this.formData.status
          // }
          // this.formSearch.industry = obj.industry;
          // this.formSearch.tenderMode = obj.tenderMode;
          // this.formSearch.status = obj.status;
          // this.industryChangeFn(obj.industry);
          // this.searchInitFn();
          // this.handleSearchFn(); //接口会重复
          const p = {
            isSystem: "YES",
            industryType: obj.industry || this.formSearch.industry,
            tenderMode: obj.tenderMode || this.formSearch.tenderMode,
            segment: obj.status || this.formSearch.status
          };
          console.log("p2", p);
          const res = await itemDictionaryAll(p);
          if (res.success) {
            this.shixiangData = res.data;
            this.subtaskListAllFn(obj);
            //  res.data;
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      shixiangDataChange(e) {
        this.shixiangDataChildrenZC = [];
        this.shixiangDataChildrenYC = [];
        const arr = [];
        const arrs = [];
        this.shixiangData.map((titem) => {
          if (e === titem.itemCode) {
            titem.children.forEach((jitem) => {
              if (jitem.itemStatus === "NORMAL_TYPE") {
                arr.push({
                  isSystem: jitem.isSystem,
                  itemStatus: jitem.itemStatus,
                  defaultItem: jitem.defaultItem,
                  sceneRecord: jitem.itemName,
                  itemCode: jitem.itemCode,
                  itemConfigId: jitem.itemConfigId
                });
                // this.shixiangDataChildrenZC.push(jitem);
              } else {
                arrs.push({
                  isSystem: jitem.isSystem,
                  itemStatus: jitem.itemStatus,
                  defaultItem: jitem.defaultItem,
                  sceneRecord: jitem.itemName,
                  itemCode: jitem.itemCode,
                  itemConfigId: jitem.itemConfigId
                });
                // this.shixiangDataChildrenYC.push(jitem);
              }
              this.FormData = {
                valueCode: titem.isSystem,
                jianzheng: titem.itemCode,
                domains: arr,
                domainss: arrs
              };
            });
          }
        });
        // this.tableTaskList.forEach((i) => {
        //   this.shixiangData.forEach((j) => {
        //     if (i.itemName == j.itemName) {
        //       j.disabled = true;
        //     }
        //   });
        // });
      },
      changeCodDomainZC() {
        this.FormData.domains.map((ditem) => {
          this.shixiangDataChildrenZC.map((titem) => {
            if (ditem.itemCode == titem.itemCode) {
              titem.disabled = true;
            }
          });
        });
      },
      changeCodDomainYC(e) {
        this.FormData.domainss.map((ditem) => {
          this.shixiangDataChildrenYC.map((titem) => {
            if (ditem.itemCode == titem.itemCode) {
              titem.disabled = true;
            }
          });
        });
      },
      removeDomains(item) {
        const index = this.FormData.domainss.indexOf(item);
        if (this.xugai === "XG") {
          if (item.isSystem === "NO" || !item.sceneRecord) {
            if (index !== -1) {
              this.FormData.domainss.splice(index, 1);
            }
            if (item.itemConfigId) {
              this.deleteIds.push(item.itemConfigId);
            }
            if (item.defaultItem === "DEFAULT") {
              this.FormData.domainss[0].defaultItem = "DEFAULT";
            }
          } else if (item.isSystem === "YES") {
            this.$message({
              type: "warning",
              message: "系统数据不可删除",
              single: true
            });
          } else if (index !== -1) {
            this.FormData.domainss.splice(index, 1);
          }
        } else {
          if (index !== -1) {
            this.FormData.domainss.splice(index, 1);
          }
          if (item.itemConfigId) {
            this.deleteIds.push(item.itemConfigId);
          }
          if (item.defaultItem === "DEFAULT") {
            this.FormData.domainss[0].defaultItem = "DEFAULT";
          }
        }
        if (this.FormData.valueCode === "YES") {
          this.shixiangDataChildrenYC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        } else {
          this.shixiangDataChildrenYC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        }
      },
      addDomains() {
        if (this.xugai === "XG") {
          if (this.FormData.valueCode === "YES") {
            this.FormData.domainss.push({
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            });
          } else {
            this.FormData.domainss.push({
              itemConfigId: "",
              itemCode: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "EXCEPTION_TYPE"
            });
          }
        } else {
          this.FormData.domainss.push({
            itemCode: "",
            sceneRecord: "",
            defaultItem: "NON_DEFAULT",
            itemStatus: "EXCEPTION_TYPE"
          });
        }
      },
      removeDomain(item) {
        console.log(item);
        const index = this.FormData.domains.indexOf(item);
        if (this.xugai === "XG") {
          if (item.isSystem === "NO" || item.sceneRecord === "") {
            if (index !== -1) {
              this.FormData.domains.splice(index, 1);
            }
            if (item.itemConfigId) {
              this.deleteIds.push(item.itemConfigId);
            }
            if (item.defaultItem === "DEFAULT") {
              this.FormData.domains[0].defaultItem = "DEFAULT";
            }
          } else if (item.isSystem === "YES") {
            this.$message({
              type: "warning",
              message: "系统数据不可删除",
              single: true
            });
          } else if (index !== -1) {
            this.FormData.domains.splice(index, 1);
          }
        } else {
          if (index !== -1) {
            this.FormData.domains.splice(index, 1);
          }
          if (item.defaultItem === "DEFAULT") {
            this.FormData.domains[0].defaultItem = "DEFAULT";
          }
          if (item.itemConfigId) {
            this.deleteIds.push(item.itemConfigId);
          }
        }
        if (this.FormData.valueCode === "YES") {
          this.shixiangDataChildrenZC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        } else {
          this.shixiangDataChildrenZC.map((titem) => {
            if (item.itemCode === titem.itemCode) {
              titem.disabled = false;
            }
          });
        }
      },
      addDomain() {
        if (this.xugai === "XG") {
          if (this.FormData.valueCode === "YES") {
            this.FormData.domains.push({
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "NORMAL_TYPE"
            });
          } else {
            this.FormData.domains.push({
              itemCode: "",
              itemConfigId: "",
              sceneRecord: "",
              defaultItem: "NON_DEFAULT",
              itemStatus: "NORMAL_TYPE"
            });
          }
        } else {
          this.FormData.domains.push({
            itemCode: "",
            sceneRecord: "",
            defaultItem: "NON_DEFAULT",
            itemStatus: "NORMAL_TYPE"
          });
        }
      },
      ridioChange(e) {
        this.FormData.domains.forEach((i, index) => {
          if (e === index) {
            i.defaultItem = "DEFAULT";
          } else {
            i.defaultItem = "NON_DEFAULT";
          }
        });
      },
      ridioChanges(e) {
        this.FormData.domainss.forEach((i, index) => {
          if (e === index) {
            i.defaultItem = "DEFAULT";
          } else {
            i.defaultItem = "NON_DEFAULT";
          }
        });
      },
      // 页面初始化
      async moduleInitFn() {
        // const p = { moduleName: "TASK" };
        const p = { moduleName: "ITEM" };
        try {
          const res = await moduleInit(p);
          if (res.success) {
            this.TASKOBJ = res.data;
            this.liveStatusArr = [];
            this.statusOptions = [];
            // v-if="formSearch.industry && formSearch.tenderMode && formSearch.status"
            this.TASKOBJ.industryTypeAndIndustry.forEach((item, indexA) => {
              this.industryTypeAndIndustryArr.push({
                label: item.label,
                value: item.value,
                children: item.childrenIndustry
              });
              console.log("indexA", indexA);
              if (indexA === 0) {
                item.children.forEach((itemB, indexB) => {
                  const flag = this.liveStatusArr.some((itemC) => itemC.value === itemB.value);
                  if (!flag) {
                    this.liveStatusArr.push(itemB); // 交易方式
                  }
                  if (indexB === 0) {
                    itemB.children.forEach((itemD) => {
                      const flag2 = this.statusOptions.some((itemC) => itemC.value === itemD.value);
                      if (!flag2) {
                        this.statusOptions.push(itemD); // 见证环节
                      }
                    });
                  }
                });
              }
            });
            this.statusOptions;
            // <el-option v-for="item in statusOptions" :key="item.abridge" :label="item.label" :value="item.abridge" />
            // for (const key in res.data.industryTypeAndTenderMode) {
            // for (const key in res.data.industryTypeAndTenderMode) {
            //   if (Object.hasOwnProperty.call(res.data.industryTypeAndTenderMode, key)) {
            //   if (Object.hasOwnProperty.call(res.data.industryTypeAndTenderMode, key)) {
            //     const item = res.data.industryAndTenderMode[key];
            //     this.industryTypeAndIndustryArr.push({
            //       label: item.label,
            //       value: item.value,
            //       children: item.childrenIndustry
            //     });
            //   }
            // }
            this.roomNameList = res.data.roomNameList;
            this.formSearch.industry = this.TASKOBJ.industryTypeAndIndustry[0].value;
            this.formSearch.tenderMode = this.liveStatusArr[0].value;
            // 见证环节排序会乱所以等排序好了再赋值 by link 20220727
            // this.formSearch.status = this.statusOptions[0].abridge;
            // if (this.formSearch.industry === "") {
            // this.handleSearchFn(this.formSearch.industry);
            this.tenderModeChangeFn(); // 有排序功能
            // this.industryChangeFn(this.formSearch.industry);
            // }
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      industryChangeFn(val) {
        console.log("val", val);
        // const arr = this.TASKOBJ.industryTypeAndTenderMode.find((item) => item.value === this.formSearch.industry);
        const arr = this.TASKOBJ.industryTypeAndIndustry.find((item) => item.value === this.formSearch.industry);
        console.log("arr", arr);
        // statusOptions
        this.liveStatusArr = arr.children;
        console.log("this.liveStatusArr", this.liveStatusArr);
        const tenderModeFlag = this.liveStatusArr.some((item) => item.value === this.formSearch.tenderMode);
        if (!tenderModeFlag) {
          this.formSearch.tenderMode = this.liveStatusArr[0].value || "";
        }
        // 见证环节
        // const currModeObj = this.liveStatusArr.find((item) => item.value === this.formSearch.tenderMode);
        // // this.statusOptions = currModeObj.children;
        // const linkArr = [];
        // console.log("this.statusOptions", this.statusOptions);
        // console.log("this.taskObj.taskWitnessLink", this.taskObj.taskWitnessLink);
        // this.taskObj.taskWitnessLink.forEach((itemA) => {
        //   const curr = currModeObj.children.find((itemB) => itemB.abridge === itemA.value);
        //   if (curr) {
        //     linkArr.push(curr);
        //   }
        // });
        // console.log("linkArr", linkArr);
        // this.statusOptions = linkArr;
        // console.log("this.statusOptions", this.statusOptions);
        // if (!this.statusOptions.some((item) => item.abridge === this.formSearch.status)) {
        //   this.formSearch.status = this.statusOptions[0].abridge || "";
        // }
        // // const flag = this.liveStatusArr.some((item) => item.value === this.tenderMode);
        // // if (!flag) {
        // //   this.tenderMode = "";
        // // }
        // this.handleSearchFn(1);
        this.tenderModeChangeFn();
      },
      tenderModeChangeFn() {
        // 见证环节
        const currModeObj = this.liveStatusArr.find((item) => item.value === this.formSearch.tenderMode);
        // this.statusOptions = currModeObj.children;
        const linkArr = [];
        console.log("this.statusOptions", this.statusOptions);
        console.log("this.TASKOBJ.taskWitnessLink", this.TASKOBJ.taskWitnessLink);
        this.TASKOBJ.taskWitnessLink.forEach((itemA) => {
          const curr = currModeObj.children.find((itemB) => itemB.abridge === itemA.value);
          if (curr) {
            linkArr.push(curr);
          }
        });
        console.log("linkArr", linkArr);
        this.statusOptions = linkArr;
        console.log("this.statusOptions", this.statusOptions);
        if (!this.statusOptions.some((item) => item.abridge === this.formSearch.status)) {
          this.formSearch.status = this.statusOptions[0].abridge || "";
        }
        this.handleSearchFn(2);
      },
      handleSearchFn(e) {
        console.log("e===", e);
        // 执行最后一次
        // if (this.timeFlag) {
        //   return;
        // }
        // clearTimeout(this.timeFlag);
        // this.timeFlag = setTimeout(async () => {
        this.timeFlag = null;
        this.pageObj.total = 0;
        this.pageObj.currentPage = 1;
        this.listPageDictionaryFn();
        // }, 200);
      },
      listPageDictionaryFn() {
        if (this.listPageDictionaryFlag) {
          return;
        }
        clearTimeout(this.listPageDictionaryFlag);
        this.listPageDictionaryFlag = setTimeout(async () => {
          this.listPageDictionaryFlag = null;
          console.log("======");
          await this.subtaskListFn();
        }, 500);
      },
      // 见证事项列表 /gdw/witness/subtask/list
      async subtaskListFn() {
        this.loading = true;
        this.tableTaskList = [];
        try {
          const p = {
            currentPage: this.pageObj.currentPage, // 当前页数
            pageSize: this.pageObj.pageSize, // 每页条数
            tenderMode: this.formSearch.tenderMode, // 交易方式
            industryType: this.formSearch.industry, // 行业类型
            segment: this.formSearch.status // 行业类型
          };
          // listPageDictionary
          const res = await itemRuleList(p);
          if (res.success) {
            if (res.data.data.length === 0 && +this.pageObj.currentPage > 1) {
              this.pageObj.currentPage = 1;
              this.$nextTick(async () => {
                console.log("===************");
                await this.listPageDictionaryFn();
              });
              return;
            }
            this.tableTaskList = res.data.data;
            this.tableTaskLists = res.data.data.map((item) => {
              this.listChind = item.children.map((chiem) => {
                if (chiem.itemStatus === "NORMAL_TYPE") {
                  return chiem;
                }
              });
              return { label: item.itemName, value: item.itemCode };
            });
            this.pageObj.total = res.data.pageBean.count;
            this.loading = false;
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        this.loading = false;
      },
      async subtaskListAllFn(obj = {}) {
        // this.loading = true;
        try {
          const p = {
            currentPage: 1, // 当前页数
            pageSize: -1, // 每页条数
            // tenderMode: this.formSearch.tenderMode, // 交易方式
            // industryType: this.formSearch.industry, // 行业类型
            // segment: this.formSearch.status // 行业类型
            industryType: obj.industry || this.formSearch.industry,
            tenderMode: obj.tenderMode || this.formSearch.tenderMode,
            segment: obj.status || this.formSearch.status
          };
          console.log("p1", p);
          const res = await itemRuleList(p);
          if (res.success) {
            this.tableTaskListAll = res.data.data;
            const arr = JSON.parse(JSON.stringify(this.shixiangData));
            this.tableTaskListAll.forEach((i) => {
              arr.forEach((j) => {
                if (i.itemName === j.itemName && this.formSearch.tenderMode === j.tenderMode) {
                  j.disabled = true;
                }
              });
            });
            this.orderTotal = res.data.pageBean.count;
            console.log("this.orderTotal", this.orderTotal);
            this.shixiangInitData = arr;
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        // this.loading = false;
      }
    }
  };
</script>
<style lang="scss" scoped>
  .layout-search {
    ::v-deep .el-form-item__label {
      width: 114px !important;
    }
    ::v-deep .el-form-item__error {
      margin-left: 35px !important;
    }
    .fromriodr {
      ::v-deep .el-radio[data-v-e595f7fc] {
        width: 150px !important;
      }
    }
    ::v-deep .el-form.is-symbol .el-form-item__label::after {
      content: "" !important;
    }
    ::v-deep .el-radio[data-v-e595f7fc] {
      width: 80px !important;
    }
    ::v-deep .el-radio__input.is-disabled + span.el-radio__label {
      padding-left: 10px !important;
    }
  }
  .zhangC {
    padding-left: 110px;
    margin-bottom: 10px;
    position: relative;
    .zhangC-1 {
      color: #56b502;
      position: absolute;
      left: 68px;
    }
    .zhangC-radio {
      width: 455px !important;
      margin-bottom: 5px;
    }
  }
  .yiC {
    padding-left: 110px;
    margin-bottom: 10px;
    position: relative;
    .yiC-1 {
      color: #ff4b53;
      position: absolute;
      left: 68px;
    }
    .yiC-radio {
      margin-bottom: 5px;
      width: 455px !important;
    }
  }
  // .el-radio {
  //   width: 150px;
  //   overflow: hidden;
  //   white-space: nowrap;
  //   text-overflow: ellipsis;
  // }
  .font-right {
    position: relative;
    .btn {
      position: absolute;
      left: 0;
      bottom: 0;
    }
  }
  .tag-list {
    padding: 0 10px 10px;
  }
  .task-status {
    span {
      background: #ccc;
      border-radius: 50%;
      display: inline-block;
      margin-right: 4px;
      width: 24px;
      height: 24px;
      font-size: 14px;
      text-indent: 5px;
      line-height: 24px;
      overflow: hidden;
      color: #fff;
    }
    .WITNESSING {
      background: $WITNESSING;
    }
    .WITNESS_FINISHED {
      background: $WITNESS_FINISHED;
    }
    .ASSIGNED {
      background: $ASSIGNED;
    }
    .UNASSIGNED {
      background: $UNASSIGNED;
    }
  }
  .cancel-dialog {
    .info {
      padding-left: 28px;
      position: relative;
      i {
        position: absolute;
        top: 0;
        left: 0;
        color: #e6ad00;
        font-size: 18px;
        vertical-align: top;
      }
    }
  }
  // .witness-dialog{
  // }
  .hide-form-label-sign {
    ::v-deep .el-form-item__label:after {
      display: none;
    }
  }
</style>
